//
//  ReviseViewController.m
//  CoreData通讯录
//
//  Created by 邝子涵 on 15/11/22.
//  Copyright © 2015年 kuangzihan. All rights reserved.
//

#import "ReviseViewController.h"
#import "LTView.h"
#import "CoreDataManager.h"
@interface ReviseViewController ()
@property(nonatomic, strong) LTView *nameView;
@property(nonatomic, strong) LTView *sexView;
@property(nonatomic, strong) LTView *numberView;
@property(nonatomic, strong) LTView *phoneView;
@property(nonatomic, strong) LTView *qqView;
@property(nonatomic, strong) LTView *nativePlaceView;
@end

@implementation ReviseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 用LTView 来创建视图
    _nameView = [[LTView alloc] initWithFrame:CGRectMake(0, 0, 375, 50)];
    [self.view addSubview:_nameView];
    _nameView.myLabel.text = @"姓名:";
    _nameView.myTextField.text = self.stu.name;
    
    _phoneView = [[LTView alloc] initWithFrame:CGRectMake(0, 50, 375, 50)];
    [self.view addSubview:_phoneView];
    _phoneView.myLabel.text = @"电话:";
    _phoneView.myTextField.text = self.stu.phone;
    
    _numberView = [[LTView alloc] initWithFrame:CGRectMake(0, 100, 375, 50)];
    [self.view addSubview:_numberView];
    _numberView.myLabel.text = @"学号:";
    _numberView.myTextField.text = [self.stu.number stringValue];
    
    _sexView = [[LTView alloc] initWithFrame:CGRectMake(0, 150, 375, 50)];
    [self.view addSubview:_sexView];
    _sexView.myLabel.text = @"性别:";
    _sexView.myTextField.text = self.stu.sex;
    
    
    _qqView = [[LTView alloc] initWithFrame:CGRectMake(0, 200, 375, 50)];
    [self.view addSubview:_qqView];
    _qqView.myLabel.text = @"QQ:";
    _qqView.myTextField.text = self.stu.qq;
    
    _nativePlaceView = [[LTView alloc] initWithFrame:CGRectMake(0, 250, 375, 50)];
    [self.view addSubview:_nativePlaceView];
    _nativePlaceView.myLabel.text = @"籍贯:";
    _nativePlaceView.myTextField.text = self.stu.nativeplace;
    
    UIButton *reviseButton = [UIButton buttonWithType:UIButtonTypeSystem];
    reviseButton.frame = CGRectMake(157.5, 320, 60, 30);
    reviseButton.layer.borderWidth = 1;
    reviseButton.layer.cornerRadius = 5;
    [reviseButton setTitle:@"修改" forState:UIControlStateNormal];
    [self.view addSubview:reviseButton];
    [reviseButton addTarget:self action:@selector(reviseButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    NSLog(@"%@", self.stu.name);
}

- (void)reviseButtonAction:(UIButton *)button{
    [self.navigationController popToRootViewControllerAnimated:YES];
    
    [self.reviseDelegate reviseAddressBook:[[CoreDataManager defaults] reviseAddressBook:_nameView.myTextField.text phone:_phoneView.myTextField.text sex:_sexView.myTextField.text number:[NSNumber numberWithInteger:[_numberView.myTextField.text integerValue]] QQ:_qqView.myTextField.text nativePlace:_nameView.myTextField.text]];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
